package cn.signalpha.modules.shop.controller.seller;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.mp.support.Condition;
import cn.signalpha.core.mp.support.Query;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.modules.shop.entity.SellerWallet;
import cn.signalpha.modules.shop.service.SellerWalletService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * 控制器
 *
 * @author signalpha
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_SHOP_NAME + "/sys-seller/seller/wallet")
@Api(value = "钱包明细", tags = "钱包明细")
public class SpiSellerWalletController extends BaseController {

	private final SellerWalletService sellerWalletService;

    @GetMapping("/page")
    @ApiImplicitParams({
        @ApiImplicitParam(name="type", dataType = "string", value = "类型"),
        @ApiImplicitParam(name="amountType", dataType = "string", value = "金额类型"),
        @ApiImplicitParam(name="remark", dataType = "string", value = "备注"),
        @ApiImplicitParam(name="sourceId", dataType = "string", value = "来源id"),
        @ApiImplicitParam(name="sourceType", dataType = "string", value = "来源类型"),
    })
    @ApiOperation(value = "分页", notes = "")
    public R<IPage<SellerWallet>> page(@ApiIgnore @RequestParam Map<String, Object> params, Query query) {
		params.put("sellerId", getUser().getTenantId());
        QueryWrapper<SellerWallet> wrapper = sellerWalletService.selectSellerWalletWrapper(params);
        return R.data(sellerWalletService.page(Condition.getPage(query), wrapper));
    }

	@GetMapping("/info")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<SellerWallet> info(@ApiParam(value = "主键", required = true) @RequestParam Long id) {
		return R.data(sellerWalletService.getById(id));
	}

	@GetMapping("/amount")
	@ApiOperation(value = "统计", notes = "")
	public R amount(@ApiIgnore @RequestParam Map<String, Object> params) {
		return R.data(sellerWalletService.sumAmountByParams(params));
	}

}
